﻿using SimpleInjector;
using Sustainalytics.Synchronization.Interface;
using Sustainalytics.Entities.RiskRatings;
using Sustainalytics.MongoDB.Extensions;
using System.Collections.Generic;

namespace Sustainalytics.ClientDW.Synchronization.RiskRatingsBenchmarks
{
    public static class SimpleInjectorConfig
    {
        public static Container Register(ILogger logger, Dictionary<string, string> gaConnectionStrings)
        {
            var container = new Container();

            container.RegisterCollections(gaConnectionStrings);

            container.RegisterMisc(logger);

            container.Verify();

            return container;
        }

        private static void RegisterCollections(this Container container, Dictionary<string, string> gaConnectionStrings)
        {
            var riskRatingsResearchConnectionString = gaConnectionStrings["RiskRatingsResearchDW"];

            container.Register(() => MongoFactory.GetCollectionFromDatabase<CoreRiskRatingResearchProfile>(riskRatingsResearchConnectionString));
            container.Register(() => MongoFactory.GetCollectionFromDatabase<RiskRatingResearchProfile>(riskRatingsResearchConnectionString));
            container.Register(() => MongoFactory.GetCollectionFromDatabase<RiskRatingHistoricalDataSet>(riskRatingsResearchConnectionString));
            container.Register(() => MongoFactory.GetCollectionFromDatabase<RiskRatingHistoricalData>(riskRatingsResearchConnectionString));
            container.Register(() => MongoFactory.GetCollectionFromDatabase<RiskRatingBenchmark>(riskRatingsResearchConnectionString));
            container.Register(() => MongoFactory.GetCollectionFromDatabase<PeerAggregate>(riskRatingsResearchConnectionString));
            container.Register(() => MongoFactory.GetCollectionFromDatabase<RiskRatingMaterialEsgIssue>(riskRatingsResearchConnectionString));
            container.Register(() => MongoFactory.GetCollectionFromDatabase<RiskRatingMeiSubPeerGroupAverage>(riskRatingsResearchConnectionString));
            container.Register(() => MongoFactory.GetCollectionFromDatabase<RiskRatingCluster>(riskRatingsResearchConnectionString));
        }

        private static void RegisterMisc(this Container container, ILogger logger)
        {
            container.Register(() => logger, Lifestyle.Singleton);

            container.Register<RiskRatingsHistoricalDataSync>();
        }
    }
}
